//
//  MCResueGoodsCell.swift
//  StoreManage
//
//  Created by MC on 2018/6/26.
//  Copyright © 2018年 MC. All rights reserved.
//

import UIKit

class MCResueGoodsCell: UICollectionViewCell {
    
    
    public var model: MCResueGoodsModel = MCResueGoodsModel() {
        
        didSet {
            iconImageView.sd_setImage(with: URL.init(string: model.goodsImage), placeholderImage: #imageLiteral(resourceName: "Reuse_placeholder_1_1"))
            nameLabel.text = model.goodsName
            
            moneyLabel.text = MCString_judgemantDecimalsIsZero(figure: model.salePrice.intValue)
            
            
            let lowest = model.salePrice.floatValue
            let suggest = model.suggestedPrice.floatValue
            
            if lowest >= suggest {
                suggestLabel.isHidden = true
            } else {
                suggestLabel.isHidden = false
                let suggestStr : String = MCString_judgemantDecimalsIsZero(figure: model.suggestedPrice.intValue)
                let att = suggestStr.MCAttributedString_deleteLine(color: UIColor.MCGray_middle)
                suggestLabel.attributedText = att
            }
            
        }

    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI() {
        
        self.addSubview(bgView)
        bgView.snp.remakeConstraints { (make) -> Void in
            make.edges.equalTo(self)
        }
        
        bgView.addSubview(iconImageView)
        iconImageView.snp.remakeConstraints { (make) -> Void in
            make.left.top.equalTo(bgView)
            make.width.height.equalTo(bgView.snp.width)
        }
        
        bgView.addSubview(nameLabel)
        nameLabel.snp.remakeConstraints { (make) -> Void in
            make.top.equalTo(iconImageView.snp.bottom).offset(12)
            make.height.equalTo(12)
            make.left.right.equalTo(bgView)
        }
        
        bgView.addSubview(moneyLabel)
        moneyLabel.snp.remakeConstraints { (make) -> Void in
            make.left.equalTo(iconImageView).offset(2)
            make.top.equalTo(nameLabel.snp.bottom).offset(6)
            make.height.equalTo(12)
        }
        
        bgView.addSubview(suggestLabel)
        suggestLabel.snp.remakeConstraints { (make) -> Void in
            make.left.equalTo(moneyLabel.snp.right).offset(2)
            make.top.equalTo(nameLabel.snp.bottom).offset(6)
            make.height.equalTo(12)
        }
        
    }
    
    
    
    
    private lazy var bgView: UIView = {
        let bgView = UIView()
        bgView.backgroundColor = UIColor.white
        return bgView
    }()
    
    private lazy var iconImageView: UIImageView = {
        let iconImageView = UIImageView()
        iconImageView.layer.borderColor = UIColor.MCGray_light.cgColor
        iconImageView.layer.borderWidth = 1
        return iconImageView
    }()
    
    private lazy var nameLabel: UILabel = {
        let name = UILabel()
        name.font = MCFont(12)
        name.textColor = UIColor.MCWords
        return name
    }()
    
    private lazy var moneyLabel: UILabel = {
        let money = UILabel()
        money.font = MCFont(13)
        money.textColor = UIColor.MCMain
        return money
    }()
    
    private lazy var suggestLabel: UILabel = {
        let money = UILabel()
        money.font = MCFont(13)
        money.textColor = UIColor.MCGray_middle
        return money
    }()
}
